package com.briup.mt.service.impl;

import com.briup.mt.bean.Dataset;
import com.briup.mt.bean.DatasetExample;
import com.briup.mt.dao.DatasetMapper;
import com.briup.mt.service.IDatasetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author wyq
 * @create 2020-12-16 17:14
 */
@Service
public class DatasetServiceImpl implements IDatasetService {
    @Autowired
    private DatasetMapper datasetMapper;

    @Override
    public List<Dataset> query(String name) {
        DatasetExample example = new DatasetExample();
        if (!StringUtils.isEmpty(name)) {
            example.createCriteria().andNameLike("%" + name + "%");
        }
        List<Dataset> list = datasetMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(Dataset dataset) {
        if (dataset.getId() == null) {
            datasetMapper.insert(dataset);
        } else {
            datasetMapper.updateByPrimaryKey(dataset);
        }
    }

    @Override
    public void deleteById(long id) {
        datasetMapper.deleteByPrimaryKey(id);
    }
}
